package com.john.pplay.common;

import android.os.Handler;
import android.os.Message;

import com.john.pplay.util.MsgCode;
import com.john.pplay.util.MyLog;

import tv.danmaku.ijk.media.player.IMediaPlayer;

/**
 * Created by stark on 2018/6/30.
 */

public class PlayerListener implements IPlayerListener {

    private Handler handler;
    public PlayerListener(Handler handler){
        this.handler = handler;
    }
    @Override
    public void onBufferingUpdate(IMediaPlayer iMediaPlayer, int i) {
//        MyLog.PrintLog(iMediaPlayer.toString(),"onBufferingUpdate "+i);
    }

    @Override
    public void onCompletion(IMediaPlayer iMediaPlayer) {
        MyLog.PrintLog(iMediaPlayer.toString(),"onCompletion");
    }

    @Override
    public boolean onError(IMediaPlayer iMediaPlayer, int i, int i1) {
        Message msg = handler.obtainMessage(MsgCode.ERROR);
        msg.arg1 = i;
        msg.arg2 = i1;
        handler.sendMessage(msg);
        return false;
    }

    @Override
    public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i1) {
        MyLog.PrintLog(iMediaPlayer.toString(),"onInfo "+i+" , "+i1);
        Message msg = handler.obtainMessage(MsgCode.INFO);
        msg.arg1 = i;
        msg.arg2 = i1;
        handler.sendMessage(msg);
        return false;
    }

    @Override
    public void onPrepared(IMediaPlayer iMediaPlayer) {
        handler.sendEmptyMessage(MsgCode.PREPARE);
    }

    @Override
    public void onSeekComplete(IMediaPlayer iMediaPlayer) {
        Message msg = handler.obtainMessage(MsgCode.SEEK_COMPLETE);
        handler.sendMessage(msg);
        MyLog.PrintLog(iMediaPlayer.toString(),"onSeekComplete");
    }

    @Override
    public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2, int i3) {
        Message msg = handler.obtainMessage(MsgCode.CHANGE_SIZE);
        msg.arg1 = i;
        msg.arg2 = i1;
        handler.sendMessage(msg);
    }
}
